<template>
  <div class="entry_box">
    <el-breadcrumb separator-class="el-icon-arrow-right" class="entry_main_box">
      <el-breadcrumb-item :to="{ path: '/backIndex/teams' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>参赛作品</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="table_box">
      <el-table
          v-loading="loading"
          :data="entry"
          border
          style="
      margin: 40px auto">
        <el-table-column
            label="比赛名称"
            align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.gameName }}</span>
          </template>
        </el-table-column>
        <el-table-column
            label="队名"
            align="center">
          <template slot-scope="scope">
            <el-tag type="success">{{ scope.row.groupName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
            label="作品名称"
            align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.workName">{{ scope.row.workName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
            label="作品状态"
            align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.workStatus }}</span>
          </template>
        </el-table-column>
        <el-table-column
            label="排名"
            align="center">
          <template slot-scope="scope">
            <span v-if="!scope.row.ranking">{{ '暂无排名'}}</span>
            <span>{{ scope.row.ranking }}</span>
          </template>
        </el-table-column>
        <el-table-column
            label="上传作品"
            align="center">
          <template slot-scope="scope">
            <el-button
                type="primary"
                size="medium"

                @click="uploading(scope.$index, scope.row)">点击去上传</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>

export default {
  name: "entry",
  data() {
    return{
      entry:[],
      loading: true
    }
  },
  methods: {
    uploading(index, row) {
      window.sessionStorage.setItem('groupID',row.groupID);
      window.sessionStorage.setItem('workName',row.workName);
      this.$router.push('/backIndex/uploading')
    },

  //  通过EntryGetOwnSignup()拿到grupID来获取作品信息
    async getEntry(data){
      this.entry.splice(0,this.entry.length);
      const teams = await this.$api.getgroups(data);
      let temp = teams.data.getInfo;
      const gruopID = {groupID: temp.groupID}
      const teachers = await this.$api.getGroupTeacherInfo(temp.groupID);
      temp.teacher = teachers.data.getGroupTeacherInfo;
      const work = await this.$api.getWorkInfo(temp.groupID);
      temp.workName = work.data.work.title;
      const workStatus = await this.$api.getWorkStatus(gruopID);
      temp.workStatus = workStatus;
      const ranking = await this.$api.getRanking(gruopID);
      if(temp.workStatus === '作品已上传' && ranking.data.status === '您的评分已结束'){
        temp.ranking = ranking.data['yourRanks:'];
      }
      this.entry.push(temp);
    },

  //  获取自己参加的比赛
    EntryGetOwnSignup(){
      this.loading = true;
      this.$api.getOwnGroupList()
        .then(res => {
          const a = res.data.info.length;
          if(res.success && a){
            res.data.info.forEach(temp => {
              this.getEntry(temp.groupID);
            });
          }
        });
      setTimeout(()=>{
        this.loading = false;
      },1500);
    }
  },
  mounted() {
    this.EntryGetOwnSignup();
  }
}
</script>

<style lang="less" scoped>
.entry_box{
  .entry_main_box{
    margin-bottom: 20px;
  }
  .table_box{
    background-color: #ffff;
    padding: 40px;
    box-shadow: 0 2px 7px rgba(187, 172, 172, 0.49), 0 5px 11px rgba(247, 231, 231, 0.36);
  }
}
</style>
